USE Clinic
GO

SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE up_DoctorsSelect
	
AS
BEGIN
	SET NOCOUNT ON;
SELECT *
	FROM 
	[Doctors]
END
GO

CREATE PROCEDURE up_DoctorsUpdate
	@UserId uniqueidentifier
	, @DoctorID int
	, @Code nvarchar(50)
	, @FirstName nvarchar(30)
	, @MiddleName nvarchar(30)
	, @LastName nvarchar(30)
	, @EGN nvarchar(20)
	, @Room int
	, @Address nvarchar(100) 
	, @Phone nvarchar(20)
	, @Email nvarchar(250)
AS 
BEGIN 
	SET NOCOUNT ON;
	
	UPDATE [Doctors]
	SET 
		[Code] = @Code
		, [FirstName] = @FirstName
		, [MiddleName] = @MiddleName
		, [LastName] = @LastName
		, [EGN] = @EGN
		, [Room] = @Room
		, [Address] = @Address
		, [Phone] = @Phone
		, [Email] = @Email
		, [UserId] = @UserId
	WHERE 
		[DoctorID] = @DoctorID
END
GO

CREATE PROCEDURE up_DoctorsDelete
	@DoctorID int
AS 
BEGIN
	SET NOCOUNT ON;
	DELETE 
	FROM 
		[Doctors] 
	WHERE 
		[DoctorID] = @DoctorID
END
GO
	
CREATE PROCEDURE up_DoctorsInsert
	@UserId uniqueidentifier
	, @DoctorID int
	, @Code nvarchar(50)
	, @FirstName nvarchar(30)
	, @MiddleName nvarchar(30)
	, @LastName nvarchar(30)
	, @EGN nvarchar(20)
	, @Room int
	, @Address nvarchar(100) 
	, @Phone nvarchar(20)
	, @Email nvarchar(250)
AS
BEGIN
	SET NOCOUNT ON;
	INSERT INTO [Doctors]
	(
		[UserId]
		, [Code]
		, [FirstName]
		, [MiddleName]
		, [LastName]
		, [EGN]
		, [Room]
		, [Address]
		, [Phone]
		, [Email]
		) 
		VALUES 
		(
			@UserId
			, @Code
			, @FirstName
			, @MiddleName
			, @LastName
			, @EGN
			, @Room
			, @Address
			, @Phone
			, @Email
		)		
END
GO

CREATE PROCEDURE up_DoctorsSelectById
	@DoctorID int
AS
BEGIN
	SET NOCOUNT ON;
	SELECT TOP 1 *
	FROM 
		Doctors
	WHERE (DoctorID = @DoctorID)
END
GO

CREATE PROCEDURE up_DoctorsGetByUserId
	@UserId uniqueidentifier
AS
BEGIN
	SET NOCOUNT ON;
	SELECT TOP 1 *
	FROM 
		Doctors
	WHERE 
		@UserId = UserId
END
GO
